package com.hsoft.zhxy.app.xtgl_02_01.service.impl;


import com.hsoft.zhxy.app.xtgl_02_01.mapper.JcggDmflXbMapper;
import com.hsoft.zhxy.app.common.model.entity.JcggDmflXb;
import com.hsoft.zhxy.app.xtgl_02_01.service.JcggDmflXbService;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.hsoft.zhxy.common.base.BaseService;
import com.hsoft.zhxy.common.result.ResultBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

 /**
 * All rights Reserved, Designed By 哈尔滨工业大学软件工程股份有限公司
 * 
 * @Title: 代码分类校标 Service层接口实现类
 * @Package 
 * @Description: 
 * @author: system
 * @date: 2020-10-26
 */
@Log4j2
@Service
public class JcggDmflXbServiceImpl extends BaseService implements JcggDmflXbService {

    @Autowired
    private JcggDmflXbMapper jcggDmflXbMapper;


    /**
     * 查询单条数据
     * @param jcggDmflXb
     * @return
     */
    public JSONObject findOne(JcggDmflXb jcggDmflXb) {
        JcggDmflXb rs = jcggDmflXbMapper.selectOne(new QueryWrapper<JcggDmflXb>().setEntity(jcggDmflXb));
        return ResultBody.setData(rs);
    }


    /**
     * 查询列表数据
     * @param jcggDmflXb
     * @return
     */
    public JSONObject findList(JcggDmflXb jcggDmflXb) {
        List<JcggDmflXb> list = jcggDmflXbMapper.selectList(new QueryWrapper<JcggDmflXb>().setEntity(jcggDmflXb));
        return ResultBody.setData(list);
    }


    /**
     * 查询分页数据
     * @param jcggDmflXb
     * @param page
     * @param pageSize
     * @return
     */
    public JSONObject findListByPage(JcggDmflXb jcggDmflXb, long page, long pageSize) {

        Page<JcggDmflXb> pageObj = new Page<JcggDmflXb>(page, pageSize);
        IPage<JcggDmflXb> result = jcggDmflXbMapper.selectPage(pageObj, new QueryWrapper<JcggDmflXb>().setEntity(jcggDmflXb));

        return ResultBody.setData(result.getTotal(), result.getRecords());
    }


    /**
     * 新增
     * @param jcggDmflXb
     * @return
     */
    public JSONObject add(JcggDmflXb jcggDmflXb) {
        jcggDmflXb.setCjsj(LocalDateTime.now());
        jcggDmflXb.setCjr(getYhid());
        jcggDmflXb.setBgsj(LocalDateTime.now());
        jcggDmflXb.setBgr(getYhid());
        return ResultBody.setData(jcggDmflXbMapper.insert(jcggDmflXb));
    }


    /**
     * 修改
     * @param jcggDmflXb
     * @return
     */
    public JSONObject update(JcggDmflXb jcggDmflXb) {
        jcggDmflXb.setBgsj(LocalDateTime.now());
        jcggDmflXb.setBgr(getYhid());
        return ResultBody.setData(jcggDmflXbMapper.updateById(jcggDmflXb));
    }


    /**
     * 删除
     * @param jcggDmflXb
     * @return
     */
    public JSONObject delete(JcggDmflXb jcggDmflXb) {
        return ResultBody.setData(jcggDmflXbMapper.delete(new QueryWrapper<JcggDmflXb>().setEntity(jcggDmflXb)));
    }


}
